<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo">
              <a-input v-model="model.orderNo" placeholder="请输入订单编号" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskName">
              <a-input v-model="model.taskName" placeholder="请输入任务名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerName">
              <a-input v-model="model.customerName" placeholder="请输入客户名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerPhone">
              <a-input v-model="model.customerPhone" placeholder="请输入客户电话" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户税号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerTaxId">
              <a-input v-model="model.customerTaxId" placeholder="请输入客户税号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单模型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderModel">
              <j-upload v-model="model.orderModel"  ></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderImages">
              <j-image-upload isMultiple  v-model="model.orderImages" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模型数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="modelCount">
              <a-input-number v-model="model.modelCount" placeholder="请输入模型数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模型克重" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="modelWeight">
              <a-input-number v-model="model.modelWeight" placeholder="请输入模型克重" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上机克重" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machineWeight">
              <a-input-number v-model="model.machineWeight" placeholder="请输入上机克重" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单克金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quotePerGram">
              <a-input v-model="model.quotePerGram" placeholder="请输入单克金额" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预估金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="estimatedAmount">
              <a-input-number v-model="model.estimatedAmount" placeholder="请输入预估金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualAmount">
              <a-input-number v-model="model.actualAmount" placeholder="请输入实际金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designAmount">
              <a-input-number v-model="model.designAmount" placeholder="请输入设计金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="已收金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receivedAmount">
              <a-input-number v-model="model.receivedAmount" placeholder="请输入已收金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下单时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderTime">
              <j-date placeholder="请选择下单时间" v-model="model.orderTime" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="requiredDeliveryTime">
              <j-date placeholder="请选择交付时间" v-model="model.requiredDeliveryTime" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总工期/天" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalDays">
              <a-input v-model="model.totalDays" placeholder="请输入总工期/天" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerRequirements">
              <a-textarea v-model="model.customerRequirements" rows="4" placeholder="请输入客户要求" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单子类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderType">
              <j-dict-select-tag type="radio" v-model="model.orderType" dictCode="order_type" placeholder="请选择单子类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="货款状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentStatus">
              <j-dict-select-tag type="radio" v-model="model.paymentStatus" dictCode="payment_status" placeholder="请选择货款状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryMethod">
              <j-dict-select-tag type="radio" v-model="model.deliveryMethod" dictCode="delivery_method" placeholder="请选择发货方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商务人员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessPerson">
              <j-select-user-by-dep v-model="model.businessPerson" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentStatus">
              <a-input v-model="model.currentStatus" placeholder="请输入当前状态" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remarks">
              <a-textarea v-model="model.remarks" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="存在问题点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="issues">
              <a-textarea v-model="model.issues" rows="4" placeholder="请输入存在问题点" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designPlannedStart">
              <j-date placeholder="请选择设计计划开始时间" v-model="model.designPlannedStart" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计计划结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designPlannedEnd">
              <j-date placeholder="请选择设计计划结束时间" v-model="model.designPlannedEnd" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计实际交付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designActualEnd">
              <j-date placeholder="请选择设计实际交付时间" v-model="model.designActualEnd" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计实际工时(小时)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designActualHours">
              <a-input-number v-model="model.designActualHours" placeholder="请输入设计实际工时(小时)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计签字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designSignature">
              <a-input v-model="model.designSignature" placeholder="请输入设计签字" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designRemarks">
              <a-textarea v-model="model.designRemarks" rows="4" placeholder="请输入设计备注" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计节点进度跟进" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designProgressTracking">
              <a-textarea v-model="model.designProgressTracking" rows="4" placeholder="请输入设计节点进度跟进" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商务确认计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessPlannedStart">
              <j-date placeholder="请选择商务确认计划开始时间" v-model="model.businessPlannedStart" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商务确认计划结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessPlannedEnd">
              <j-date placeholder="请选择商务确认计划结束时间" v-model="model.businessPlannedEnd" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商务实际确认时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessActualConfirm">
              <j-date placeholder="请选择商务实际确认时间" v-model="model.businessActualConfirm" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商务实际工时(小时)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessActualHours">
              <a-input-number v-model="model.businessActualHours" placeholder="请输入商务实际工时(小时)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商务签字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessSignature">
              <a-input v-model="model.businessSignature" placeholder="请输入商务签字" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商务备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessRemarks">
              <a-textarea v-model="model.businessRemarks" rows="4" placeholder="请输入商务备注" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="编程计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programmingPlannedStart">
              <j-date placeholder="请选择编程计划开始时间" v-model="model.programmingPlannedStart" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="编程计划结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programmingPlannedEnd">
              <j-date placeholder="请选择编程计划结束时间" v-model="model.programmingPlannedEnd" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="编程实际交付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programmingActualEnd">
              <j-date placeholder="请选择编程实际交付时间" v-model="model.programmingActualEnd" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="编程实际工时(小时)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programmingActualHours">
              <a-input-number v-model="model.programmingActualHours" placeholder="请输入编程实际工时(小时)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="编程签字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programmingSignature">
              <a-input v-model="model.programmingSignature" placeholder="请输入编程签字" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="编程备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programmingRemarks">
              <a-textarea v-model="model.programmingRemarks" rows="4" placeholder="请输入编程备注" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="编程节点进度跟进" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programmingProgressTracking">
              <a-textarea v-model="model.programmingProgressTracking" rows="4" placeholder="请输入编程节点进度跟进" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionPlannedStart">
              <j-date placeholder="请选择生产计划开始时间" v-model="model.productionPlannedStart" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产计划结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionPlannedEnd">
              <j-date placeholder="请选择生产计划结束时间" v-model="model.productionPlannedEnd" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产实际交付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionActualEnd">
              <j-date placeholder="请选择生产实际交付时间" v-model="model.productionActualEnd" style="width: 100%" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产实际总工时(小时)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionActualHours">
              <a-input-number v-model="model.productionActualHours" placeholder="请输入生产实际总工时(小时)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产签字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionSignature">
              <a-input v-model="model.productionSignature" placeholder="请输入生产签字" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionRemarks">
              <a-textarea v-model="model.productionRemarks" rows="4" placeholder="请输入生产备注" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产节点进度跟进" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionProgressTracking">
              <a-textarea v-model="model.productionProgressTracking" rows="4" placeholder="请输入生产节点进度跟进" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计工期占比(≤30%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designDurationRatio">
              <a-input-number v-model="model.designDurationRatio" placeholder="请输入设计工期占比(≤30%)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商务工期占比(≤10%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessDurationRatio">
              <a-input-number v-model="model.businessDurationRatio" placeholder="请输入商务工期占比(≤10%)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="编程工期占比(≤30%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="programmingDurationRatio">
              <a-input-number v-model="model.programmingDurationRatio" placeholder="请输入编程工期占比(≤30%)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产工期占比(≥30%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionDurationRatio">
              <a-input-number v-model="model.productionDurationRatio" placeholder="请输入生产工期占比(≥30%)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "YjOrderModal_Payment",
    components: { 
    },
    data () {
      return {
        title:"操作",
        width:800,
        visible: false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
           taskName: [
              { required: true, message: '请输入任务名称!'},
           ],
           customerName: [
              { required: true, message: '请输入客户名称!'},
           ],
           customerPhone: [
              { required: true, message: '请输入客户电话!'},
           ],
           modelCount: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           modelWeight: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           machineWeight: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           quotePerGram: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           estimatedAmount: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           actualAmount: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           designAmount: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           receivedAmount: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           orderTime: [
              { required: true, message: '请输入下单时间!'},
           ],
           totalDays: [
              { required: false},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
           ],
           orderType: [
              { required: true, message: '请输入单子类型!'},
           ],
           paymentStatus: [
              { required: true, message: '请输入货款状态!'},
           ],
           deliveryMethod: [
              { required: true, message: '请输入发货方式!'},
           ],
           businessPerson: [
              { required: true, message: '请输入商务人员!'},
           ],
        },
        url: {
          add: "/erp/yjOrder/add",
          edit: "/erp/yjOrder/edit",
        }
     
      }
    },
    created () {
    //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false
          }
        })
      },
      handleCancel () {
        this.close()
      },

      
    }
  }
</script>